package com.smkj.kaoqin.common.aspect;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.smkj.kaoqin.common.utils.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class MyMetaObjectHandle implements MetaObjectHandler {
//    插入操作的时候执行该方法
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("insert公共字段自动填充...{}",metaObject.getOriginalObject());
        metaObject.setValue("createTime", LocalDateTime.now());// 给createTime属性自动填充值
//        metaObject.setValue("updateTime",LocalDateTime.now());
//        metaObject.setValue("createUser", BaseContext.getInfo());//获取当前管理员id
//        metaObject.setValue("updateUser",BaseContext.getInfo());
    }
 
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("update公共字段自动填充... {}",metaObject.getOriginalObject());
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("updateUser",BaseContext.getInfo());
    }
}